import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {LocalStorProvider} from "../../providers/local-stor/local-stor";
import {ApiProvider} from "../../providers/api/api";
import {PersonRankingPage} from "../person-ranking/person-ranking";

/**
 * Generated class for the MyScoreListPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-my-score-list',
  templateUrl: 'my-score-list.html',
})
export class MyScoreListPage {

  user_id;

  scoreList;

  // 是否存在继续授课时的padding;
  padding = 0;
  constructor(public navCtrl: NavController, public navParams: NavParams,private storage:LocalStorProvider,public http: ApiProvider) {
  }

/*  ionViewDidLoad() {
    this.user_id=this.navParams.get("student_id");
    this.getScoreList();
  }*/

  ionViewDidEnter()
  {
    this.user_id=this.navParams.get("student_id");
    this.getScoreList();
  }

  /**
   * 获取成绩列表
   */
  getScoreList()
  {
    this.http.post("/userstu/myScorelist.do",{studentId:this.user_id}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],"bottom");
      }
      else
      {
        this.scoreList=item["scoreList"];
      }
    })
  }

  /**
   * 获取相应班课成绩排名
   * @param classcourseId
   */
  getRanking(classcourseId)
  {
    this.navCtrl.push(PersonRankingPage,{class_course_id:+classcourseId,student_id:this.user_id});
  }

  /**
   * 下拉刷新
   * @param refresher
   */
  doRefresh(refresher)
  {
    this.http.post("/userstu/myScorelist.do",{studentId:this.user_id}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],"bottom");
      }
      else
      {
        setTimeout(() => {
          this.scoreList=item["scoreList"];
          refresher.complete();
        },2000);
      }
    })
  }
}
